﻿using NPOI.SS.UserModel;

namespace Soul.Excel
{
    internal class DefaultExcelStyles
    {
        public ICellStyle ColumnStyle { get; }

        public ICellStyle TitleStyle { get; }

        public DefaultExcelStyles(IWorkbook book, int columnFontSize, int titleFontSize)
        {
            var font1 = book.CreateFont();
            //font1.FontName = "宋体";
            font1.IsBold = true;
            font1.FontHeight = columnFontSize;
            ColumnStyle = book.CreateCellStyle();
            InitStyle(ColumnStyle);
            ColumnStyle.Alignment = HorizontalAlignment.Center;
            ColumnStyle.VerticalAlignment = VerticalAlignment.Center;
            ColumnStyle.SetFont(font1);

            var font2 = book.CreateFont();
            //font2.FontName = "宋体";
            font2.IsBold = true;
            font2.FontHeight = titleFontSize;
            TitleStyle = book.CreateCellStyle();
            InitStyle(TitleStyle);
            TitleStyle.Alignment = HorizontalAlignment.Center;
            TitleStyle.VerticalAlignment = VerticalAlignment.Center;
            TitleStyle.SetFont(font2);
        }

        public static void InitStyle(ICellStyle style)
        {
            style.BorderBottom = BorderStyle.Thin;
            style.BorderTop = BorderStyle.Thin;
            style.BorderLeft = BorderStyle.Thin;
            style.BorderRight = BorderStyle.Thin;
            style.WrapText = true;
        }
    }
}
